package com.ruoyi.web.controller.departmental;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.departmental.domain.HisDepartmentalSection;
import com.ruoyi.departmental.service.IHisDepartmentalSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科室Controller
 * 
 * @author ruoyi
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/departmental/section")
public class HisDepartmentalSectionController extends BaseController
{
    @Autowired
    private IHisDepartmentalSectionService hisDepartmentalSectionService;

    /**
     * 查询科室列表
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisDepartmentalSection hisDepartmentalSection)
    {
        startPage();
        List<HisDepartmentalSection> list = hisDepartmentalSectionService.selectHisDepartmentalSectionList(hisDepartmentalSection);
        return getDataTable(list);
    }

    /**
     * 导出科室列表
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:export')")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HisDepartmentalSection hisDepartmentalSection)
    {
        List<HisDepartmentalSection> list = hisDepartmentalSectionService.selectHisDepartmentalSectionList(hisDepartmentalSection);
        ExcelUtil<HisDepartmentalSection> util = new ExcelUtil<HisDepartmentalSection>(HisDepartmentalSection.class);
        util.exportExcel(response, list, "科室数据");
    }

    /**
     * 获取科室详细信息
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:query')")
    @GetMapping(value = "/{sectionId}")
    public AjaxResult getInfo(@PathVariable("sectionId") Long sectionId)
    {
        return success(hisDepartmentalSectionService.selectHisDepartmentalSectionBySectionId(sectionId));
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:add')")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HisDepartmentalSection hisDepartmentalSection)
    {
        return toAjax(hisDepartmentalSectionService.insertHisDepartmentalSection(hisDepartmentalSection));
    }

    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:edit')")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisDepartmentalSection hisDepartmentalSection)
    {
        return toAjax(hisDepartmentalSectionService.updateHisDepartmentalSection(hisDepartmentalSection));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('departmental:section:remove')")
    @Log(title = "科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sectionIds}")
    public AjaxResult remove(@PathVariable Long[] sectionIds)
    {
        return toAjax(hisDepartmentalSectionService.deleteHisDepartmentalSectionBySectionIds(sectionIds));
    }
}
